<!doctype html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta
            name="viewport"
            content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"
        />
        <meta
            name="format-detection"
            content="telephone=no,email=no,date=no,address=no"
        />
        <title></title>
        <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
        <style>
            body {
                background-color: #03a9f4;
            }

            #frm-container {
                margin: 5px auto;
                width: 83%;
                height: 100%;
                border-radius: 20px;
                border: 2px solid white;
                padding: 5px 10px;
                background: white;
            }

            #footer {
                background: none;
                position: absolute;
                bottom: 0;
            }
        </style>
    </head>

    <body>
        <header class="aui-bar aui-bar-nav" id="aui-header">
            <div class="aui-pull-left aui-btn" onclick="close_win();">
                <span class="aui-iconfont aui-icon-left"></span>返回
            </div>
        </header>

        <div id="frm-container" class="aui-content-padded">
            <div
                class="aui-tab aui-margin-t-10 aui-margin-b-5 aui-font-size-18"
            >
                <div style="color: #03a9f4; margin: 0 auto">短信重置密码</div>
            </div>
            <div
                class="aui-hr"
                style="
                    width: 90%;
                    margin: 0 auto;
                    border-top: 0.05rem solid #03a9f4;
                "
            ></div>
            <section class="aui-content-padded"></section>
            <section class="aui-content-padded">
                <div
                    class="aui-searchbar"
                    id="search"
                    style="
                        margin-bottom: 1rem;
                        background-color: #ffffff;
                        width: 100%;
                    "
                >
                    <div
                        class="aui-searchbar-input aui-border-radius"
                        style="
                            margin: 0rem;
                            height: 1.8rem;
                            border: 1px solid #459bde;
                            background-color: transparent;
                        "
                    >
                        <div
                            class="aui-iconfont aui-icon-mobile"
                            style="
                                width: 16px;
                                font-size: 12px;
                                margin-top: 3px;
                            "
                        ></div>
                        <div
                            style="
                                margin-top: 7px;
                                margin-right: 8px;
                                height: 21px;
                                width: 1px;
                                border-left: 1px #459bde solid;
                            "
                        ></div>
                        <input
                            style="margin-top: 3px; font-size: 0.8rem"
                            type="number"
                            placeholder="请输入手机号"
                            id="login_username"
                        />
                        <div class="aui-searchbar-clear-btn">
                            <i class="aui-iconfont aui-icon-close"></i>
                        </div>
                    </div>
                    <div class="aui-searchbar-btn" tapmode>取消</div>
                </div>
                <div
                    class="aui-searchbar"
                    id="search"
                    style="
                        margin-bottom: 1rem;
                        background-color: #ffffff;
                        width: 100%;
                    "
                >
                    <div
                        class="aui-searchbar-input aui-border-radius"
                        style="
                            width: 60%;
                            margin: 0rem;
                            height: 1.8rem;
                            border: 1px solid #459bde;
                            background-color: transparent;
                        "
                    >
                        <div
                            class="aui-iconfont aui-icon-mail"
                            style="
                                width: 16px;
                                font-size: 12px;
                                margin-top: 3px;
                            "
                        ></div>
                        <div
                            style="
                                margin-top: 7px;
                                margin-right: 8px;
                                height: 21px;
                                width: 1px;
                                border-left: 1px #459bde solid;
                            "
                        ></div>
                        <input
                            style="margin-top: 3px; font-size: 0.8rem"
                            type="number"
                            placeholder="短信验证码"
                            id="msgcode"
                        />
                        <div class="aui-searchbar-clear-btn">
                            <i class="aui-iconfont aui-icon-close"></i>
                        </div>
                    </div>
                    <!-- <div id="sendValidcode"class="aui-btn aui-btn-block  aui-btn-sm aui-font-size-12" style="text-align:center;width:35%;margin-left:5%;background-color:#03a9f4" tapmode onclick="sms();">获取验证码</div> -->
                    <div
                        id="sendValidcode"
                        class="aui-btn aui-btn-block aui-btn-sm aui-font-size-12"
                        style="
                            color: #ffffff;
                            text-align: center;
                            width: 35%;
                            margin-left: 5%;
                            background-color: #03a9f4;
                        "
                        tapmode
                        onclick="sms();"
                    >
                        获取验证码
                    </div>
                    <!-- <div class="aui-searchbar-btn" tapmode>取消</div> -->
                </div>

                <div
                    class="aui-searchbar"
                    id="search"
                    style="
                        margin-bottom: 1rem;
                        background-color: #ffffff;
                        width: 100%;
                    "
                >
                    <div
                        class="aui-searchbar-input aui-border-radius"
                        style="
                            margin: 0rem;
                            height: 1.8rem;
                            border: 1px solid #459bde;
                            background-color: transparent;
                        "
                    >
                        <div
                            class="aui-iconfont aui-icon-lock"
                            style="
                                width: 16px;
                                font-size: 12px;
                                margin-top: 3px;
                            "
                        ></div>
                        <div
                            style="
                                margin-top: 7px;
                                margin-right: 8px;
                                height: 21px;
                                width: 1px;
                                border-left: 1px #459bde solid;
                            "
                        ></div>
                        <input
                            style="margin-top: 3px; font-size: 0.8rem"
                            type="password"
                            placeholder="请输入新密码（6-16位字符）"
                            id="new_password"
                        />
                        <div class="aui-searchbar-clear-btn">
                            <i class="aui-iconfont aui-icon-close"></i>
                        </div>
                    </div>
                    <div class="aui-searchbar-btn" tapmode>取消</div>
                </div>
                <div
                    class="aui-searchbar"
                    id="search"
                    style="
                        margin-bottom: 1rem;
                        background-color: #ffffff;
                        width: 100%;
                    "
                >
                    <div
                        class="aui-searchbar-input aui-border-radius"
                        style="
                            margin: 0rem;
                            height: 1.8rem;
                            border: 1px solid #459bde;
                            background-color: transparent;
                        "
                    >
                        <div
                            class="aui-iconfont aui-icon-lock"
                            style="
                                width: 16px;
                                font-size: 12px;
                                margin-top: 3px;
                            "
                        ></div>
                        <div
                            style="
                                margin-top: 7px;
                                margin-right: 8px;
                                height: 21px;
                                width: 1px;
                                border-left: 1px #459bde solid;
                            "
                        ></div>
                        <input
                            style="margin-top: 3px; font-size: 0.8rem"
                            type="password"
                            placeholder="请再次输入新密码"
                            id="new_confirm_password"
                        />
                        <div class="aui-searchbar-clear-btn">
                            <i class="aui-iconfont aui-icon-close"></i>
                        </div>
                    </div>
                    <div class="aui-searchbar-btn" tapmode>取消</div>
                </div>
                <div
                    class="aui-btn aui-btn-block aui-btn-info aui-btn-sm aui-font-size-18"
                    style="margin-top: 1rem; margin-bottom: 0.5rem"
                    onclick="finish();"
                >
                    确认
                </div>
                <div
                    class="aui-font-size-30"
                    style="text-align: center; color: #459bde"
                    onclick="close_win();"
                >
                    取消
                </div>
            </section>
        </div>
    </body>
    <script type="text/javascript" src="../../script/api.js"></script>
    <script>
        function close_win() {
            api.openWin({
                name: "MainMenu",
                url: "./../MainMenu.html",
                reload: true,
            });
        }
    </script>
    <!-- <script type="text/javascript" src="../../script/smsVerify.js"></script> -->
    <!-- <script type="text/javascript">
    var smsVerify = null;
    var n = 0;
    var intervalID;
    apiready = function() {
       smsVerify = api.require("smsVerify");
      register();
      api.parseTapmode();
        //适配iOS7+，Android4.4+状态栏沉浸式效果，详见config文档statusBarAppearance字段
        $api.fixStatusBar($api.byId('aui-header'));
        $api.css($api.byId('frm-container'), 'height:' + api.frameHeight * 1.37 + 'px;')
    }
    function register(){
      smsVerify.register(function(ret, err){
        if(ret.status){
          //api.alert({msg: '注册成功'});
          console.log('注册成功');
        }else{
          // api.alert({msg: err.code+' 注册失败'});
        }
      });
    }
    //add by gxl
    function setEnable() {
        n++;
        if (n > 0 && n <= 60) {
                document.getElementById("sendValidcode").innerText = "重新发送(" + (60 - n) + "s)";
              //  document.getElementById("sendValidcode").removeEventListener("click", sms, false);
                document.getElementById("sendValidcode").disabled = true;
                document.getElementById("sendValidcode").style.backgroundColor = '#B8B8B8';
                document.getElementById("sendValidcode").style.color = '#000000';

        } else {
                document.getElementById("sendValidcode").innerText = "获取验证码";
                //document.getElementById("sendValidcode").addEventListener("click", sms, false);
                document.getElementById("sendValidcode").disabled = false;
                document.getElementById("sendValidcode").style.backgroundColor = '#03a9f4';
                document.getElementById("sendValidcode").style.color = '#ffffff';

                window.clearInterval(intervalID);
                n=0;
        }
    }
    //获取短信验证码
    function sms(){
      if ($api.val($api.byId('login_username')) == "") {
          api.toast({
              msg: "手机号不能为空",
              duration: 2000,
              location: 'bottom'
          });
          return;
      }
      if ($api.val($api.byId('login_username')).length != 11) {
          api.toast({
              msg: "手机号格式错误",
              duration: 2000,
              location: 'bottom'
          });
          return;
      }
      var phoneNum = document.getElementById("login_username").value;
      intervalID = window.setInterval("setEnable()", 1000);
      smsVerify.sms({
        phone:phoneNum,
      },function(ret, err){
        if(ret.status){
          // 新增的安卓智能验证功能
          /*if( ret.smart == true ){	// 安卓版特有功能 智能验证成功
            api.alert({msg: '智能验证成功，开发者可以为用户直接跳转到手机号验证成功之后的操作'});
          }else{
           api.alert({msg: '短信发送成功'});
          }
          */
           api.alert({msg: '短信发送成功'});
          return true;
        }else{
          api.alert({msg: ' 短信发送失败'});
          return false;
        }
      });
    }
    function form_check() {
        if ($api.val($api.byId('login_username')).trim() == "") {
            api.toast({
                msg: "手机号或用户名不能为空",
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }
        if ($api.val($api.byId('login_username')).length != 11) {
            api.toast({
                msg: "手机号格式错误",
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }
        if ($api.val($api.byId('new_password')).trim() == "") {
            api.toast({
                msg: "密码不能为空",
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }
        if ($api.val($api.byId('new_confirm_password')).trim() == "") {
            api.toast({
                msg: "请再次输入密码",
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }
        if ($api.val($api.byId('new_password')).length < 6 || $api.val($api.byId('new_password')).length > 16) {
            api.toast({
                msg: "密码长度 6 - 16 位",
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }
        if ($api.val($api.byId('msgcode')).trim() == ""){
            api.toast({
                msg: '验证码不能为空',
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }
        if ($api.val($api.byId('new_password')) != $api.val($api.byId('new_confirm_password'))) {
            api.toast({
                  msg:"两次密码不一致，请重新输入！",
                  duration: 2000,
                  location:'bottom'
            });
            return false;
        }
        return true;
    }
    function finish(){
      if(!form_check()) return;
      var phone = document.getElementById("login_username").value;
      var code = document.getElementById("msgcode").value;
      smsVerify.verify({
        phone:phone,
        code:code,
      },function(ret, err){
        if(ret.status){
          console.log('注册验证码验证成功')
          $api.removeCls($api.byId("waiting_gif"), "aui-hide");
              // 普通登录
              api.ajax({
                  url: $api.getStorage("api_url") + '/lansys/user/forgetPassword',
                  method: 'post',
                  timeout: 5,
                  data: {
                      values: {
                          phoneNum: $api.val($api.byId('login_username')),
                          newPassword: $api.val($api.byId('new_password')),
                      }
                  }
              }, function(ret, err) {
                  $api.addCls($api.byId("waiting_gif"), "aui-hide");
                  if (ret) {
                      var response = JSON.stringify(ret);
                      if (ret.result == "success") {
                          delete ret.result;
                          //console.log(JSON.stringify(ret));
                          api.openWin({
                              name: 'mainPage',
                              url: '../login_win.html',
                              slidBackEnabled: false
                          });
                      } else {
                          api.toast({
                              msg: decodeURI(ret.msg),
                              duration: 2000,
                              location: 'bottom'
                          });
                      }
                  } else {
                      api.toast({
                          msg: err,
                          duration: 2000,
                          location: 'bottom'
                      });
                      //console.log(JSON.stringify(err));
                  }
              });
        }else{
          api.alert({msg: '短信验证码验证失败'});
        }
      });
    }
    function close_win() {
        api.closeWin({});
    }
</script> -->
</html>
